﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:ICSharpCode.Profiler.Controls"
>
    <Style x:Key="CustomGridViewScrollViewerStyle"
	       TargetType="{x:Type ScrollViewer}">
        <Setter Property="Focusable" Value="false" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <DockPanel Margin="{TemplateBinding Padding}">
                            <ScrollViewer DockPanel.Dock="Top" 
							              HorizontalScrollBarVisibility="Hidden" 
							              VerticalScrollBarVisibility="Hidden"
							              Focusable="false">
                                <GridViewHeaderRowPresenter
									SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
									ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}"
									ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}"
									ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}"
									ColumnHeaderStringFormat="{Binding Path=TemplatedParent.View.ColumnHeaderStringFormat, RelativeSource={RelativeSource TemplatedParent}}"
									AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}"
									ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}"
									ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}"
								>
                                    <GridViewHeaderRowPresenter.Columns>
                                        <Binding Path="TemplatedParent.View.Columns" RelativeSource="{RelativeSource TemplatedParent}" />
                                    </GridViewHeaderRowPresenter.Columns>
                                </GridViewHeaderRowPresenter>
                            </ScrollViewer>

                            <DockPanel DockPanel.Dock="Bottom">
                                <ScrollBar
									Name="Column0ScrollBar"
									Orientation="Horizontal"
									Minimum="0.0"
									Maximum="{Binding Path=TemplatedParent.View.MaxOverflowWidth, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
									ViewportSize="{Binding Path=TemplatedParent.View.Columns[0].ActualWidth, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
									Visibility="Visible"
									Cursor="Arrow"
									Value="{Binding Path=TemplatedParent.View.CurrentScrollPosition, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
									DockPanel.Dock="Left"
									Width="{Binding Path=TemplatedParent.View.Columns[0].ActualWidth, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"/>
                                <Rectangle Fill="{Binding Path=Background, ElementName=Column0ScrollBar}"/>
                            </DockPanel>

                            <ScrollContentPresenter Name="PART_ScrollContentPresenter" 
								KeyboardNavigation.DirectionalNavigation="Local"
								Content="{TemplateBinding Content}" 
								ContentTemplate="{TemplateBinding ContentTemplate}" 
								CanContentScroll="{TemplateBinding CanContentScroll}" 
								SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </DockPanel>
                        <ScrollBar Name="PART_HorizontalScrollBar" 
						           Orientation="Horizontal" 
						           Grid.Row="1" 
						           Minimum="0.0" Maximum="{TemplateBinding ScrollableWidth}" 
						           ViewportSize="{TemplateBinding ViewportWidth}" 
						           Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" 
						           Cursor="Arrow"
						           Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
                        <ScrollBar Name="PART_VerticalScrollBar"
						           Orientation="Vertical"
						           Grid.Column="1" 
						           Minimum="0.0" Maximum="{TemplateBinding ScrollableHeight}"
						           ViewportSize="{TemplateBinding ViewportHeight}" 
						           Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" 
						           Cursor="Arrow" 
						           Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
                        <DockPanel Grid.Column="1" Grid.Row="1" 
						           LastChildFill="False"
						           Background="{Binding Path=Background, ElementName=PART_VerticalScrollBar}">
                            <Rectangle DockPanel.Dock="Left" Width="1" Fill="White" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />
                            <Rectangle DockPanel.Dock="Top" Height="1" Fill="White" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" />
                        </DockPanel>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Static local:CustomGridView.CustomGridViewStyle}"
	       TargetType="{x:Type ListView}"
	       BasedOn="{StaticResource {x:Static GridView.GridViewStyleKey}}">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListView">
                    <Border Name="Bd"
					        Background="{TemplateBinding Panel.Background}"
					        BorderBrush="{TemplateBinding Border.BorderBrush}"
					        BorderThickness="{TemplateBinding Border.BorderThickness}"
					        SnapsToDevicePixels="True">
                        <DockPanel>
                            <ScrollViewer Padding="{TemplateBinding Control.Padding}"
							              Style="{StaticResource CustomGridViewScrollViewerStyle}">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </ScrollViewer>
                        </DockPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>